﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.UI.HtmlControls;
using _0912276_ChatClient.DTO;

namespace _0912276_ChatClient.UserControl
{
    public partial class wuc_SuaThongTinTaiKhoan : System.Web.UI.UserControl
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            if (!IsPostBack)
            {

                if (id != null)
                {
                    MemberShip member = BO.SearchMember.FindMemberWithId(int.Parse(id));
                    tbFirstName.Text = member.FirstName;
                    tbLastName.Text = member.LastName;
                    tbSalary.Text = member.Salary.ToString();
                    if (member.Gender)
                        rbMale.Checked = true;
                    RBFemale.Checked = true;
                    cldDOB.SelectedDate = member.DOBirth;
                    HiddenField1.Value = id;
                }
                
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Search.aspx");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                MemberShip mb = new MemberShip();
                mb.Key = int.Parse(HiddenField1.Value.Trim());
                mb.FirstName = tbFirstName.Text.Trim();
                mb.LastName = tbLastName.Text.Trim();
                if (rbMale.Checked)
                    mb.Gender = true;
                mb.Gender = false;
                mb.DOBirth = cldDOB.SelectedDate;
                mb.Salary = int.Parse(tbSalary.Text.Trim());
                BO.MemberShipBO.UpdateMember(mb);
                Response.Redirect("~/Search.aspx");
            }
            catch (Exception ex)
            {
                Response.Redirect("~/AddMember.aspx");
            }
            Response.Redirect("~/RegularMember.aspx");
        }          
    }
}